home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / dflat_r_.arc / DFLAT.H < prev    next >
Text File  |  1991-10-02  |  18KB  |  433 lines

  1. /* ------------- dflat.h ----------- */
  2. #ifndef WINDOW_H
  3. #define WINDOW_H
  4.  
  5. #define VERSION "Version 6"
  6.  
  7. #define TRUE 1
  8. #define FALSE 0
  9.  
  10. extern char DFlatApplication[];
  11.  
  12. #define INCLUDE_SYSTEM_MENUS
  13. #define INCLUDE_CLOCK
  14. #define INCLUDE_MULTIDOCS
  15. #define INCLUDE_SHADOWS
  16. #define INCLUDE_DIALOG_BOXES
  17. #define INCLUDE_HELP
  18. #define INCLUDE_STATUSBAR
  19. #define PUSHBUTTON_DEPRESS
  20. #define INCLUDE_COMPRESS_HELPFILE
  21. #define INCLUDE_CLIPBOARD
  22. #define INCLUDE_SCROLLBARS
  23. #define INCLUDE_MULTILINE
  24.  
  25. #ifdef TESTING_DFLAT
  26. #define INCLUDE_LOGGING
  27. #define INCLUDE_RELOADHELP
  28. #endif
  29.  
  30. #define MAXMESSAGES 50
  31. #define DELAYTICKS 1
  32. #define FIRSTDELAY 7
  33. #define DOUBLETICKS 5
  34.  
  35. typedef enum messages {
  36. #ifdef WATCOM
  37.     WATCOMFIX1 = -1,
  38. #endif
  39.     #undef DFlatMsg
  40.     #define DFlatMsg(m) m,
  41.     #include "dflatmsg.h"
  42.     MESSAGECOUNT
  43. } MESSAGE;
  44.  
  45. typedef enum window_class    {
  46. #ifdef WATCOM
  47.     WATCOMFIX2 = -1,
  48. #endif
  49.     #define ClassDef(c,b,p,a) c,
  50.     #include "classes.h"
  51.     CLASSCOUNT
  52. } CLASS;
  53.  
  54. #include "system.h"
  55. #include "config.h"
  56. #include "rect.h"
  57. #include "menu.h"
  58. #include "keys.h"
  59. #include "commands.h"
  60. #include "dialbox.h"
  61.  
  62. /* ------ integer type for message parameters ----- */
  63. typedef long PARAM;
  64.  
  65. typedef struct window {
  66.     CLASS class;           /* window class                  */
  67.     char *title;           /* window title                  */
  68.     struct window *parent; /* parent window                 */
  69.     int (*wndproc)
  70.         (struct window *, enum messages, PARAM, PARAM);
  71.     /* ----------------- window colors -------------------- */
  72.     char WindowColors[4][2];
  73.     /* ---------------- window dimensions ----------------- */
  74.     RECT rc;               /* window coordinates
  75.                                             (0/0 to 79/24)  */
  76.     int ht, wd;            /* window height and width       */
  77.     RECT RestoredRC;       /* restored condition rect       */
  78.     /* -------------- linked list pointers ---------------- */
  79.     struct window *nextfocus;   /* next window on screen    */
  80.     struct window *prevfocus;   /* previous window on screen*/
  81.     struct window *nextbuilt;   /* next window built        */
  82.     struct window *prevbuilt;   /* previous window built    */
  83.  
  84.     int attrib;                 /* Window attributes        */
  85.     char *videosave;            /* video save buffer        */
  86.     int condition;              /* Restored, Maximized,
  87.                                    Minimized, Closing       */
  88.     int restored_attrib;        /* attributes when restored */
  89.     void *extension;      /* menus, dialogs, documents, etc */
  90.     struct window *PrevMouse;
  91.     struct window *PrevKeyboard;
  92.     struct window *MenuBarWnd;/* menu bar                   */
  93.     struct window *StatusBar; /* status bar                 */
  94.     /* ----------------- text box fields ------------------ */
  95.     int wlines;     /* number of lines of text              */
  96.     int wtop;       /* text line that is on the top display */
  97.     unsigned char *text;   /* window text                   */
  98.     unsigned int textlen;  /* text length                   */
  99.     int wleft;      /* left position in window viewport     */
  100.     int textwidth;  /* width of longest line in textbox     */
  101.     int BlkBegLine; /* beginning line of marked block       */
  102.     int BlkBegCol;  /* beginning column of marked block     */
  103.     int BlkEndLine; /* ending line of marked block          */
  104.     int BlkEndCol;  /* ending column of marked block        */
  105.     int HScrollBox; /* position of horizontal scroll box    */
  106.     int VScrollBox; /* position of vertical scroll box      */
  107.     unsigned int *TextPointers; /* -> list of line offsets    */
  108.     /* ----------------- list box fields ------------------ */
  109.     int selection;  /* current selection                    */
  110.     int AddMode;    /* adding extended selections mode      */
  111.     int AnchorPoint;/* anchor point for extended selections */
  112.     int SelectCount;/* count of selected items              */
  113.     /* ----------------- edit box fields ------------------ */
  114.     int CurrCol;    /* Current column                       */
  115.     int CurrLine;   /* Current line                         */
  116.     int WndRow;     /* Current window row                   */
  117.     int TextChanged; /* TRUE if text has changed            */
  118.     unsigned char *DeletedText; /* for undo                 */
  119.     int DeletedLength; /*  "   "                            */
  120.     /* ---------------- dialog box fields ----------------- */
  121.     void *dFocus;          /* control that has the focus    */
  122.     int ReturnCode;        /* return code from a dialog box */
  123.     int Modal;               /* True if a modeless dialog box */
  124.     /* -------------- popdownmenu fields ------------------ */
  125.     MENU *mnu;        /* points to menu structure             */
  126.     MBAR *holdmenu; /* previous active menu                 */
  127.     /* --------------- help box fields -------------------- */
  128.     void *firstword; /* -> first in list of key words       */
  129.     void *lastword;  /* -> last in list of key words        */
  130.     void *thisword;  /* -> current in list of key words     */
  131.     /* -------------- status bar fields ------------------- */
  132.     int TimePosted;  /* True if time has been posted        */
  133. } * WINDOW;
  134.  
  135. #include "classdef.h"
  136. #include "video.h"
  137.  
  138. enum Condition     {
  139.     ISRESTORED, ISMINIMIZED, ISMAXIMIZED, ISCLOSING
  140. };
  141.  
  142. void LogMessages (WINDOW, MESSAGE, PARAM, PARAM);
  143. void MessageLog(WINDOW);
  144. /* ------- window methods ----------- */
  145. #define ICONHEIGHT 3
  146. #define ICONWIDTH  10
  147. #define WindowHeight(w)      ((w)->ht)
  148. #define WindowWidth(w)       ((w)->wd)
  149. #define BorderAdj(w)         (TestAttribute(w,HASBORDER)?1:0)
  150. #define TopBorderAdj(w)      ((TestAttribute(w,HASTITLEBAR) &&   \
  151.                               TestAttribute(w,HASMENUBAR)) ?  \
  152.                               2 : (TestAttribute(w,HASTITLEBAR | \
  153.                               HASMENUBAR | HASBORDER) ? 1 : 0))
  154. #define ClientWidth(w)       (WindowWidth(w)-BorderAdj(w)*2)
  155. #define ClientHeight(w)      (WindowHeight(w)-TopBorderAdj(w)-\
  156.                               BorderAdj(w))
  157. #define WindowRect(w)        ((w)->rc)
  158. #define GetTop(w)            (RectTop(WindowRect(w)))
  159. #define GetBottom(w)         (RectBottom(WindowRect(w)))
  160. #define GetLeft(w)           (RectLeft(WindowRect(w)))
  161. #define GetRight(w)          (RectRight(WindowRect(w)))
  162. #define GetClientTop(w)      (GetTop(w)+TopBorderAdj(w))
  163. #define GetClientBottom(w)   (GetBottom(w)-BorderAdj(w))
  164. #define GetClientLeft(w)     (GetLeft(w)+BorderAdj(w))
  165. #define GetClientRight(w)    (GetRight(w)-BorderAdj(w))
  166. #define GetParent(w)         ((w)->parent)
  167. #define GetTitle(w)          ((w)->title)
  168. #define NextWindow(w)        ((w)->nextfocus)
  169. #define PrevWindow(w)        ((w)->prevfocus)
  170. #define NextWindowBuilt(w)   ((w)->nextbuilt)
  171. #define PrevWindowBuilt(w)   ((w)->prevbuilt)
  172. #define GetClass(w)          ((w)->class)
  173. #define GetAttribute(w)      ((w)->attrib)
  174. #define AddAttribute(w,a)    (GetAttribute(w) |= a)
  175. #define ClearAttribute(w,a)  (GetAttribute(w) &= ~(a))
  176. #define TestAttribute(w,a)   (GetAttribute(w) & (a))
  177. #define isWndVisible(w)      (GetAttribute(w) & VISIBLE)
  178. #define SetVisible(w)        (GetAttribute(w) |= VISIBLE)
  179. #define ClearVisible(w)      (GetAttribute(w) &= ~VISIBLE)
  180. #define gotoxy(w,x,y) cursor(w->rc.lf+(x)+1,w->rc.tp+(y)+1)
  181. WINDOW CreateWindow(CLASS,char *,int,int,int,int,void*,WINDOW,
  182.        int (*)(struct window *,enum messages,PARAM,PARAM),int);
  183. void AddTitle(WINDOW, char *);
  184. void InsertTitle(WINDOW, char *);
  185. void DisplayTitle(WINDOW, RECT *);
  186. void RepaintBorder(WINDOW, RECT *);
  187. void ClearWindow(WINDOW, RECT *, int);
  188. #ifdef INCLUDE_SYSTEM_MENUS
  189. void clipline(WINDOW, int, char *);
  190. #else
  191. #define clipline(w,x,c) /**/
  192. #endif
  193. void writeline(WINDOW, char *, int, int, int);
  194. void InitWindowColors(WINDOW);
  195.  
  196. void SetNextFocus(WINDOW);
  197. void SetPrevFocus(WINDOW);
  198. void SkipSystemWindows(int);
  199. void RemoveFocusWindow(WINDOW);
  200. void AppendFocusWindow(WINDOW);
  201. void RemoveBuiltWindow(WINDOW);
  202. void AppendBuiltWindow(WINDOW);
  203. WINDOW GetFirstChild(WINDOW);
  204. WINDOW GetNextChild(WINDOW, WINDOW);
  205. WINDOW GetLastChild(WINDOW);
  206. WINDOW GetPrevChild(WINDOW, WINDOW);
  207. WINDOW GetFirstFocusChild(WINDOW);
  208. WINDOW GetNextFocusChild(WINDOW, WINDOW);
  209.  
  210. int isVisible(WINDOW);
  211. int CharInView(WINDOW, int, int);
  212. void PutWindowChar(WINDOW, int, int, int);
  213. void GetVideoBuffer(WINDOW);
  214. void RestoreVideoBuffer(WINDOW);
  215. void CreatePath(char *, char *, int, int);
  216. int LineLength(char *);
  217. RECT AdjustRectangle(WINDOW, RECT);
  218. #define BaseWndProc(class,wnd,msg,p1,p2)    \
  219.     (*classdefs[DerivedClass(class)].wndproc)(wnd,msg,p1,p2)
  220. #define DefaultWndProc(wnd,msg,p1,p2)         \
  221.     (classdefs[wnd->class].wndproc == NULL) ? \
  222.     BaseWndProc(wnd->class,wnd,msg,p1,p2) :      \
  223.     (*classdefs[wnd->class].wndproc)(wnd,msg,p1,p2)
  224. #define NULLWND ((WINDOW) 0)
  225. struct LinkedList    {
  226.     WINDOW FirstWindow;
  227.     WINDOW LastWindow;
  228. };
  229. extern struct LinkedList Focus;
  230. extern struct LinkedList Built;
  231. extern WINDOW inFocus;
  232. extern WINDOW CaptureMouse;
  233. extern WINDOW CaptureKeyboard;
  234. extern int foreground, background;
  235. extern int WindowMoving;
  236. extern int WindowSizing;
  237. extern int TextMarking;
  238. extern int VSliding;
  239. extern int HSliding;
  240. extern char *Clipboard;
  241. extern int VSliding;
  242. extern int HSliding;
  243. /* --------- space between menubar labels --------- */
  244. #define MSPACE 2
  245. /* --------------- border characters ------------- */
  246. #define FOCUS_NW      (unsigned char) '\xc9'
  247. #define FOCUS_NE      (unsigned char) '\xbb'
  248. #define FOCUS_SE      (unsigned char) '\xbc'
  249. #define FOCUS_SW      (unsigned char) '\xc8'
  250. #define FOCUS_SIDE    (unsigned char) '\xba'
  251. #define FOCUS_LINE    (unsigned char) '\xcd'
  252. #define NW            (unsigned char) '\xda'
  253. #define NE            (unsigned char) '\xbf'
  254. #define SE            (unsigned char) '\xd9'
  255. #define SW            (unsigned char) '\xc0'
  256. #define SIDE          (unsigned char) '\xb3'
  257. #define LINE          (unsigned char) '\xc4'
  258. #define LEDGE         (unsigned char) '\xc3'
  259. #define REDGE         (unsigned char) '\xb4'
  260. /* ------------- scroll bar characters ------------ */
  261. #define UPSCROLLBOX    (unsigned char) '\x1e'
  262. #define DOWNSCROLLBOX  (unsigned char) '\x1f'
  263. #define LEFTSCROLLBOX  (unsigned char) '\x11'
  264. #define RIGHTSCROLLBOX (unsigned char) '\x10'
  265. #define SCROLLBARCHAR  (unsigned char) 176 
  266. #define SCROLLBOXCHAR  (unsigned char) 178
  267. /* ------------------ menu characters --------------------- */
  268. #define CHECKMARK      (unsigned char) (SCREENHEIGHT==25?251:4)
  269. #define CASCADEPOINTER (unsigned char) '\x10'
  270. /* ----------------- title bar characters ----------------- */
  271. #define CONTROLBOXCHAR (unsigned char) '\xf0'
  272. #define MAXPOINTER     24      /* maximize token            */
  273. #define MINPOINTER     25      /* minimize token            */
  274. #define RESTOREPOINTER 18      /* restore token             */
  275. /* --------------- text control characters ---------------- */
  276. #define APPLCHAR     (unsigned char) 176 /* fills application window */
  277. #define SHORTCUTCHAR '~'    /* prefix: shortcut key display */
  278. #define CHANGECOLOR  (unsigned char) 174 /* prefix to change colors  */
  279. #define RESETCOLOR   (unsigned char) 175 /* reset colors to default  */
  280. #define LISTSELECTOR   4    /* selected list box entry      */
  281. /* --------- message prototypes ----------- */
  282. void init_messages(void);
  283. void PostMessage(WINDOW, MESSAGE, PARAM, PARAM);
  284. int SendMessage(WINDOW, MESSAGE, PARAM, PARAM);
  285. int dispatch_message(void);
  286. int TestCriticalError(void);
  287. /* ---- standard window message processing prototypes ----- */
  288. int ApplicationProc(WINDOW, MESSAGE, PARAM, PARAM);
  289. int NormalProc(WINDOW, MESSAGE, PARAM, PARAM);
  290. int TextBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  291. int ListBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  292. int EditBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  293. int MenuBarProc(WINDOW, MESSAGE, PARAM, PARAM);
  294. int PopDownProc(WINDOW, MESSAGE, PARAM, PARAM);
  295. int ButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
  296. int DialogProc(WINDOW, MESSAGE, PARAM, PARAM);
  297. int SystemMenuProc(WINDOW, MESSAGE, PARAM, PARAM);
  298. int HelpBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  299. int MessageBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  300. int ErrorBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  301. int YesNoBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  302. int StatusBarProc(WINDOW, MESSAGE, PARAM, PARAM);
  303. /* ------------- normal box prototypes ------------- */
  304. int isWindow(WINDOW);
  305. WINDOW inWindow(int, int);
  306. void SetStandardColor(WINDOW);
  307. void SetReverseColor(WINDOW);
  308. #define HitControlBox(wnd, p1, p2)     \
  309.      (TestAttribute(wnd, CONTROLBOX) && \
  310.      p1 == 2 && p2 == 0)
  311. #define WndForeground(wnd)         \
  312.     (wnd->WindowColors [STD_COLOR] [FG])
  313. #define WndBackground(wnd)         \
  314.     (wnd->WindowColors [STD_COLOR] [BG])
  315. #define FrameForeground(wnd)     \
  316.     (wnd->WindowColors [FRAME_COLOR] [FG])
  317. #define FrameBackground(wnd)     \
  318.     (wnd->WindowColors [FRAME_COLOR] [BG])
  319. #define SelectForeground(wnd)     \
  320.     (wnd->WindowColors [SELECT_COLOR] [FG])
  321. #define SelectBackground(wnd)     \
  322.     (wnd->WindowColors [SELECT_COLOR] [BG])
  323. #define HighlightForeground(wnd)     \
  324.     (wnd->WindowColors [HILITE_COLOR] [FG])
  325. #define HighlightBackground(wnd)     \
  326.     (wnd->WindowColors [HILITE_COLOR] [BG])
  327. #define WindowClientColor(wnd, fg, bg)     \
  328.         WndForeground(wnd) = fg, WndBackground(wnd) = bg
  329. #define WindowReverseColor(wnd, fg, bg) \
  330.         SelectForeground(wnd) = fg, SelectBackground(wnd) = bg
  331. #define WindowFrameColor(wnd, fg, bg) \
  332.         FrameForeground(wnd) = fg, FrameBackground(wnd) = bg
  333. #define WindowHighlightColor(wnd, fg, bg) \
  334.         HighlightForeground(wnd) = fg, HighlightBackground(wnd) = bg
  335. /* -------- text box prototypes ---------- */
  336. #define TextLine(wnd, sel) \
  337.       (wnd->text + *((wnd->TextPointers) + sel))
  338. void WriteTextLine(WINDOW, RECT *, int, int);
  339. void SetAnchor(WINDOW, int, int);
  340. #define BlockMarked(wnd) (  wnd->BlkBegLine ||    \
  341.                             wnd->BlkEndLine ||    \
  342.                             wnd->BlkBegCol  ||    \
  343.                             wnd->BlkEndCol)
  344. #define ClearBlock(wnd) wnd->BlkBegLine = wnd->BlkEndLine =  \
  345.                         wnd->BlkBegCol  = wnd->BlkEndCol = 0;
  346. #define GetText(w)        ((w)->text)
  347. void ClearTextPointers(WINDOW);
  348. void BuildTextPointers(WINDOW);
  349. /* --------- menu prototypes ---------- */
  350. int CopyCommand(unsigned char *, unsigned char *, int, int);
  351. void PrepFileMenu(void *, struct Menu *);
  352. void PrepEditMenu(void *, struct Menu *);
  353. void PrepSearchMenu(void *, struct Menu *);
  354. void PrepWindowMenu(void *, struct Menu *);
  355. void BuildSystemMenu(WINDOW);
  356. int isActive(MBAR *, int);
  357. char *GetCommandText(MBAR *, int);
  358. int isCascadedCommand(MBAR *,int);
  359. void ActivateCommand(MBAR *,int);
  360. void DeactivateCommand(MBAR *,int);
  361. int GetCommandToggle(MBAR *,int);
  362. void SetCommandToggle(MBAR *,int);
  363. void ClearCommandToggle(MBAR *,int);
  364. void InvertCommandToggle(MBAR *,int);
  365. int BarSelection(int);
  366. /* ------------- list box prototypes -------------- */
  367. int ItemSelected(WINDOW, int);
  368. /* ------------- edit box prototypes ----------- */
  369. #ifdef INCLUDE_MULTILINE
  370. #define isMultiLine(wnd)     TestAttribute(wnd, MULTILINE)
  371. #else
  372. #define isMultiLine(wnd)     FALSE
  373. #endif
  374. /* --------- message box prototypes -------- */
  375. int GenericMessage(char *, char *, int,
  376.     int (*)(struct window *, enum messages, PARAM, PARAM),
  377.     char *, char *);
  378. #define TestErrorMessage(msg)    \
  379.     GenericMessage("Error", msg, 2, ErrorBoxProc,   Ok, Cancel)
  380. #define ErrorMessage(msg) \
  381.     GenericMessage("Error", msg, 1, ErrorBoxProc,   Ok, NULL)
  382. #define MessageBox(ttl, msg) \
  383.     GenericMessage(ttl,     msg, 1, MessageBoxProc, Ok, NULL)
  384. #define YesNoBox(msg)    \
  385.     GenericMessage(NULL,    msg, 2, YesNoBoxProc,  Yes, No)
  386. WINDOW MomentaryMessage(char *);
  387. int MsgHeight(char *);
  388. int MsgWidth(char *);
  389.  
  390. #ifdef INCLUDE_DIALOG_BOXES
  391. /* ------------- dialog box prototypes -------------- */
  392. int DialogBox(WINDOW, DBOX *, int,
  393.        int (*)(struct window *, enum messages, PARAM, PARAM));
  394. int OpenFileDialogBox(char *, char *);
  395. int SaveAsDialogBox(char *);
  396. void GetDlgListText(WINDOW, char *, enum commands);
  397. int DlgDirList(WINDOW, char *, enum commands,
  398.                             enum commands, unsigned);
  399. int RadioButtonSetting(DBOX *, enum commands);
  400. void PushRadioButton(DBOX *, enum commands);
  401. void PutItemText(WINDOW, enum commands, char *);
  402. void GetItemText(WINDOW, enum commands, char *, int);
  403. char *GetDlgTextString(DBOX *, enum commands, CLASS);
  404. void SetDlgTextString(DBOX *, enum commands, char *, CLASS);
  405. void SetCheckBox(DBOX *, enum commands);
  406. void ClearCheckBox(DBOX *, enum commands);
  407. int CheckBoxSetting(DBOX *, enum commands);
  408. CTLWINDOW *FindCommand(DBOX *, enum commands, int);
  409. WINDOW ControlWindow(DBOX *, enum commands);
  410. CTLWINDOW *ControlBox(DBOX *, WINDOW);
  411. void EnableButton(DBOX *, enum commands);
  412. void DisableButton(DBOX *, enum commands);
  413.  
  414. #define GetDlgText(db, cmd) GetDlgTextString(db, cmd, TEXT)
  415. #define GetDlgTextBox(db, cmd) GetDlgTextString(db, cmd, TEXTBOX)
  416. #define GetEditBoxText(db, cmd) GetDlgTextString(db, cmd, EDITBOX)
  417. #define SetDlgText(db, cmd, s) SetDlgTextString(db, cmd, s, TEXT)
  418. #define SetDlgTextBox(db, cmd, s) SetDlgTextString(db, cmd, s, TEXTBOX)
  419. #define SetEditBoxText(db, cmd, s) GetDlgTextString(db, cmd, s, EDITBOX)
  420.  
  421. #endif
  422.  
  423. /* ------------- help box prototypes ------------- */
  424. void LoadHelpFile(void);
  425. void UnLoadHelpFile(void);
  426. int DisplayHelp(WINDOW, char *);
  427.  
  428. #ifdef INCLUDE_HELP
  429. extern char *ClassNames[];
  430. #endif
  431.  
  432. #endif
  433.